@extends('layouts.app')

@section('content')
    <div>
        <button type="button" class="btn btn-info btn-xs add-feed"
           data-href="{{ route('feedback.create') }}"
           style="float: right">添加留言</button>
    </div>
    <h4>已经有留言({{ $data->count() }} 条)</h4>
    <hr>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th width="10">ID</th>
            <th width="80">留言者</th>
            <th width="150">标题</th>
            <th>内容</th>
            <th width="100">留言时间</th>
            <th width="100">操作</th>
        </tr>
        </thead>
        <tbody>
        @forelse($data as $record)
            <tr>
                <td>{{ $record->id }}</td>
                <td>{{ $record->user->name }}</td>
                <td>{{ $record->title }}</td>
                <td>{{ $record->content }}</td>
                <td>{{ $record->formatted_time }}</td>
                <td>
                    {{--<a href="" class="btn btn-primary">编辑</a>
                    <button type="button" class="btn btn-danger" onclick="return confirm('确认删除？')">删除</button>--}}
                </td>
            </tr>
        @empty
            <tr>
                <td colspan="100" class="text-center">暂无留言</td>
            </tr>
        @endforelse
        </tbody>
    </table>
    {{ $data->links() }}
@endsection
@section('scripts')
    <script>
        let user = @json($user);

        $(function () {
            $('.add-feed').click(function () {
                if (user == null) {
                    alert('请先登录');
                    return
                }

                location.href = $(this).data('href')
            })
        });
    </script>
@endsection
